package pat;

import java.util.Scanner;
import java.util.Vector;

class CBJ {
	public static void main(String args[]) {
		int num, Wcount[] = new int[2], Lcount[] = new int[2], Pcount[] = new int[2];
		int C[] = new int[2], J[] = new int[2], B[] = new int[2];
		int flag = 0, flag1 = 0;
		int f = 0, ff = 0;
		Scanner s = new Scanner(System.in);
		num = s.nextInt();
		char a[] = new char[num], b[] = new char[num];
		for (int i = 0; i < num; i++) {
			String str1 = s.next();
			a[i] = str1.charAt(0);
			String str2 = s.next();
			b[i] = str2.charAt(0);
		}
		for (int i = 0; i < num; i++) {
			if (a[i] == 'C' && b[i] == 'J') {
				Wcount[0]++;
				Lcount[1]++;
				C[0]++;
			}
			if (a[i] == 'J' && b[i] == 'C') {
				C[1]++;
				Wcount[1]++;
				Lcount[0]++;
			}

			if (a[i] == 'B' && b[i] == 'C') {
				B[0]++;
				Wcount[0]++;
				Lcount[1]++;
			}
			if (a[i] == 'C' && b[i] == 'B') {
				B[1]++;
				Wcount[1]++;
				Lcount[0]++;
			}

			if (a[i] == 'J' && b[i] == 'B') {
				J[0]++;
				Wcount[0]++;
				Lcount[1]++;
			}
			if (a[i] == 'B' && b[i] == 'J') {
				J[1]++;
				Wcount[1]++;
				Lcount[0]++;
			}

			if (a[i] == 'C' && b[i] == 'C') {
				Pcount[0]++;
				Pcount[1]++;
			}
			if (a[i] == 'J' && b[i] == 'J') {
				Pcount[1]++;
				Pcount[0]++;
			}
			if (a[i] == 'B' && b[i] == 'B') {
				Pcount[1]++;
				Pcount[0]++;
			}
		}

		int maxA = (C[0] > J[0]) ? (C[0] > B[0] ? C[0] : B[0])
				: (J[0] > B[0] ? J[0] : B[0]);
		int maxB = (C[1] > J[1]) ? (C[1] > B[1] ? C[1] : B[1])
				: (J[1] > B[1] ? J[1] : B[1]);

		System.out.println(Wcount[0] + " " + Pcount[0] + " " + Lcount[0]);
		System.out.println(Wcount[1] + " " + Pcount[1] + " " + Lcount[1]);
		if (maxA == B[0]) {
			System.out.print("B" + " ");
			flag = 1;
		}
		if (maxA == C[0] && flag == 0) {
			System.out.print("C" + " ");
			flag1 = 0;
		}
		if (maxA == J[0] && flag == 0 && flag1 == 0) {
			System.out.print("J" + " ");
		}

		if (maxB == B[1]) {
			System.out.print("B");
			f = 1;
		}
		if (maxB == C[1] && f == 0) {
			System.out.print("C");
			ff = 1;
		}
		if (maxB == J[1] && f == 0 && ff == 0) {
			System.out.print("J");
		}
	}
}